﻿using DocumentFormat.OpenXml.Lite.Xml;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Schema;
using System.Xml.Serialization;

namespace DocumentFormat.OpenXml.Lite.SpreadsheetML.Excel.StyleElements
{
    [XmlRoot("tableStyle", Namespace = Constants.ExcelMain)]
    public class TableStyle : XmlSerializable
    {
        [XmlAttribute("name", Form = XmlSchemaForm.Qualified)]
        public string Name { get; set; }

        [Optional]
        [XmlAttribute("pivot", Form = XmlSchemaForm.Qualified)]
        public Nullable<bool> Pivot { get; set; }

        [Optional]
        [XmlAttribute("table", Form = XmlSchemaForm.Qualified)]
        public Nullable<bool> Table { get; set; }

        [Optional]
        [XmlAttribute("count", Form = XmlSchemaForm.Qualified)]
        public Nullable<uint> Count { get; set; }

        [Optional]
        [XmlElement("tableStyleElement", Namespace = Constants.ExcelMain)]
        public XmlList<TableStyleElement> TableStyleElements { get; set; }

        public TableStyle()
        {
            TableStyleElements = new XmlList<TableStyleElement>();
        }

        /// <summary>
        /// Automatically increment 'Count'
        /// </summary>
        public void AddTableStyleElement(TableStyleElement element)
        {
            if (Count == null)
            {
                Count = 0;
            }

            Count++;
            TableStyleElements.Add(element);
        }
    }
}
